package com.koron.css2.clientCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.mapper.ValveTransferHistoryMapper;
import com.koron.css2.clientCenter.queryBean.ValveHistoryQueryBean;
import com.koron.css2.clientCenter.vo.ValveHistoryVo;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 转办历史查找
 *
 * @author cd
 */
public class ValveHistory implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            ValveHistoryQueryBean queryBean = JsonUtils.objectToPojo(req.getData(), ValveHistoryQueryBean.class);

            ValveTransferHistoryMapper openMapper = factory.getMapper(ValveTransferHistoryMapper.class);
            PageHelper.startPage(queryBean.getPage(), queryBean.getPageCount());
            List<ValveHistoryVo> list = openMapper.getList(queryBean);

            @SuppressWarnings("rawtypes")
            MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
            info.setData(new PageInfo<>(list));
            return info;
        } catch (Exception e) {
            logger.error("开关阀历史：" + e.getMessage(), e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
        }
    }
}
